package by.yativem.ins.web.actions;

import by.ins.app.AppContext;
import by.ins.app.commands.AppCommandConstants;
import by.ins.app.commands.ManagedTaskCommandBulder;
import by.ins.life.evolution.ILifeEvoluter;
import by.yativem.commons.console.ConsoleCommandBean;

public class LifeEvoluterAction extends AbstaractActonSupport {
	
	/**
	 * represent LifeEvolutor Id 
	 */
	private String lifeEvoluterName;
	
	private ILifeEvoluter<?> lifeEvoluter;
	
	private String evoluteCount ="1";
	
	public String viewLifeEvoluter(){
		this.lifeEvoluter = AppContext.getDefiendLifeEvoluter(lifeEvoluterName);
		if(lifeEvoluter == null){
			this.addActionError("No such LiveEvoluter with Id: " + lifeEvoluterName);
			return ERROR;
		}		
		return SUCCESS;
	}
	
	public String evolute(){
		this.lifeEvoluter = AppContext.getDefiendLifeEvoluter(lifeEvoluterName);
		ConsoleCommandBean cb = new ConsoleCommandBean(AppCommandConstants.COMMAND_EVOLUTE);
		cb.setParam(AppCommandConstants.COMMAND_PROP_TASK_NAME, lifeEvoluterName);
		cb.setParam(AppCommandConstants.COMMAND_PROP_EVOLUTE_COUNT, evoluteCount);
		ManagedTaskCommandBulder.buildTaskCommand(cb);
		if(lifeEvoluter == null){
			this.addActionError("No such LiveEvoluter with Id: " + lifeEvoluterName);
			return ERROR;
		}	
		
		return SUCCESS;
	}
	
	@Override
	public void validate(){
		
		
	}

	public String getLifeEvoluterName() {
		return lifeEvoluterName;
	}

	public void setLifeEvoluterName(String lifeEvoluterId) {
		this.lifeEvoluterName = lifeEvoluterId;
	}

	public ILifeEvoluter<?> getLifeEvoluter() {
		return lifeEvoluter;
	}

	public void setLifeEvoluter(ILifeEvoluter<?> lifeEvoluter) {
		this.lifeEvoluter = lifeEvoluter;
	}


}
